import moment from 'moment';
import { categoryList } from './api';

export const formItems = [
  {
    label: '活动ID',
    name: 'id',
    type: 'input',
  },
  {
    label: '活动名称',
    name: 'title',
    type: 'input',
  },
  {
    label: '所属企业',
    name: 'company_id',
    type: 'input',
  },
  {
    label: '状态',
    name: 'status',
    span: 8,
    type: 'select',
    itemProps: {
      options: [
        {
          label: '上架',
          value: 'STATUS_PUT_SHELF',
        },
        {
          label: '下架',
          value: 'STATUS_OFF_SHELF',
        },
      ],
    },
  },
  {
    label: '创建日期',
    name: 'create_at',
    span: 8,
    valueFields: ['start_at', 'end_at'],
    valueType: 'string',
    placeholder: ['开始时间', '结束时间'],
    value: [],
    type: 'range-picker',
    format: 'YYYY-MM-DD',
  },
  {
    label: '所属栏目ID',
    name: 'category_id',
    type: 'select',
    asyncOptions: {
      api: categoryList,
      handleData(data) {
        return data.list.map((item) => {
          item.label = item.title;
          item.value = item.id;
          return item;
        });
      },
    },
  },
];

export const searchRules = {
  searchName: [
    {
      required: true,
      message: 'Please input Activity name',
      trigger: 'blur',
    },
    {
      max: 15,
      message: 'Length should be max 15',
      trigger: 'blur',
    },
  ],
};

export const columns = [
  {
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    width: 200,
  },
  // {
  //   title: '序号',
  //   dataIndex: 'id',
  //   key: 'id',
  // },
  {
    title: '活动ID',
    dataIndex: 'id',
    key: 'id',
    width: 100,
  },
  {
    title: '所属企业',
    dataIndex: 'company_name',
    key: 'company_name',
    width: 200,
    slots: { customRender: 'company_name' },
  },
  {
    title: '所属栏目页ID',
    dataIndex: 'category_id',
    key: 'category_id',
    width: 200,
  },
  {
    title: '活动名称',
    dataIndex: 'title',
    key: 'title',
    width: 200,
  },
  {
    title: '奖品数量',
    dataIndex: 'prize_num',
    key: 'prize_num',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'create_time',
    key: 'create_time',
    width: 200,
    customRender(row) {
      return moment(row.record.create_time * 1000).format('YYYY-MM-DD k:mm:ss');
    },
  },
  {
    title: '活动开始时间',
    dataIndex: 'start_at',
    key: 'start_at',
    width: 200,
    customRender(row) {
      return moment(row.record.start_at * 1000).format('YYYY-MM-DD k:mm:ss');
    },
  },
  {
    title: '活动结束时间',
    dataIndex: 'end_at',
    key: 'end_at',
    width: 200,
    customRender(row) {
      return moment(row.record.end_at * 1000).format('YYYY-MM-DD k:mm:ss');
    },
  },
  {
    title: '活动地址',
    dataIndex: 'url',
    key: 'url',
    width: 200,
    slots: { customRender: 'url' },
  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
    width: 100,
    slots: { customRender: 'status' },
  },
];
